/***********************************************************************
    Written By Alex "SparkyMcSparks" Romo

    Questions? Concerns? Suggestions?
        Contact Me On AIM @ DareDevilSparks7
***********************************************************************/

Script.Load( "lua/Utility.lua" )

class 'Galaga_Scoring' ( Entity )

Galaga_Scoring.updateInterval = 0.01
Galaga_Scoring.networkVars =
    {
    }
    
function Galaga_Scoring:OnInit()
    Entity.OnInit(self)

    Galaga_Scoring.instance = self

    if (Server) then
        self:SetPropagate( Entity.Propagate_Always )
        self:SetNextThink( self.updateInterval )
    end
    
    // Misc
    self.killLast = 0
    self.killCount = { }

    // Score Vars
    self.type1Points = 10
    self.type2Points = 20
    self.type3Points = 30
    self.type4Points = 40
    
    // Multiplier Vars
    self.multiplierFadeTime = 10 // Seconds
    self.multiplierMaxed = false
    self.multiplier = 1
    self.lastMulti = 0.0 // Seconds
end

if (Server) then
    /*
    Think Update
    */
    function Galaga_Scoring:OnThink()        
        // Points Awarded
        if( self.player ~= nil and self.player.pointsAwarded ~= nil and self.player.pointsAwarded > 0 ) then
                self.player.score = self.player.score + 1
                self.player.pointsAwarded = self.player.pointsAwarded - 1
        end

        self:SetNextThink(self.updateInterval)
    end
    
    /*
    Add Score Point By Point For Sizzle
    */
    function Galaga_Scoring:AddScore( player, points )
        self.player = player
        
        local cellNum = table.maxn( self.killCount )
        
        self.killCount[ cellNum ] = { points, false }
    
        if( player.pointsAwarded == nil or player.pointsAwarded < 0 ) then
            player.pointsAwarded = 0
        end
        
        player.pointsAwarded = player.pointsAwarded + points
    end
    
    /*
    Reset Score
    */
    function Galaga_Scoring:ResetScore( player )
        player.score = 0
    end
    
    /*
    Return Kills
    */
    function Galaga_Scoring:ReturnKills()
        return kills
    end
end

Shared.LinkClassToMap( "Galaga_Scoring", "galaga_scoring", Galaga_Scoring.networkVars )